package cn.afactory.tygz.controller;

import android.content.Context;
import android.os.Handler;

import java.util.List;

import cn.afactory.tygz.model.CompanyInfoList;
import cn.afactory.tygz.model.SnsTopicInfoList;
import cn.afactory.tygz.net.NetManager;
import cn.afactory.tygz.net.lsn.OnResponseListener;
import cn.afactory.tygz.ui.base.entity.SearchHistoryEntity;
import cn.afactory.tygz.ui.base.views.search.SearchHistory;
import cn.afactory.tygz.ui.base.views.search.SearchSourcePager;
import cn.afactory.tygz.ui.base.views.search.SearchType;

/**
 * Created by Kenneth on 15/9/10.
 */
public class SearchController extends BaseLogicController {

    public static final int MSG_SEARCH_COMPANY_OK = 4000;
    public static final int MSG_SEAECH_COMPANY_KO = 4001;
    public static final int MSG_SEARCH_TOPIC_OK = 4002;
    public static final int MSG_SEAECH_TOPIC_KO = 4003;

    public SearchController(Context context, Handler handler) {
        super(context, handler);
    }

    /**
     * 搜索公司
     * @param mSearchKey
     * @param mPageIndex
     * @param mPageSize
     */
    public void searchCompany(final String mSearchKey, final int mPageIndex, final int mPageSize) {
        NetManager.getInstance(mContext).doSearchCompany(mSearchKey, mPageIndex, mPageSize, new OnResponseListener<CompanyInfoList>() {
            @Override
            public void onComplete(boolean isOK, CompanyInfoList result, int errorCode, String errorMsg) {
                if (isOK) {
                    sendMessage(MSG_SEARCH_COMPANY_OK, result);
                    return;
                }
                sendMessage(MSG_SEAECH_COMPANY_KO, errorCode, 0, errorMsg);
            }

            @Override
            public void onInternError(int errorCode, String errorMessage) {
                sendMessage(MSG_SEAECH_COMPANY_KO, errorCode, 0, errorMessage);
            }
        });
    }

    /**
     * 搜索话题
     * @param mSearchKey
     * @param mPageIndex
     * @param mPageSize
     */
    public void searchTopic(final String mSearchKey, final int mPageIndex, final int mPageSize) {
        NetManager.getInstance(mContext).doSearchTopic(mSearchKey, mPageIndex, mPageSize, new OnResponseListener<SnsTopicInfoList>() {
            @Override
            public void onComplete(boolean isOK, SnsTopicInfoList result, int errorCode, String errorMsg) {
                if (isOK) {
                    sendMessage(MSG_SEARCH_TOPIC_OK, result);
                    return;
                }
                sendMessage(MSG_SEAECH_TOPIC_KO, errorCode, 0, errorMsg);
            }

            @Override
            public void onInternError(int errorCode, String errorMessage) {
                sendMessage(MSG_SEAECH_TOPIC_KO, errorCode, 0, errorMessage);
            }
        });
    }


}
